import { theNextDayTime } from "../../ui-utils/Foundation";
import * as API_Goods from '../../api/goods'
import * as API_Trade from '../../api/trade'
import { formatPrice } from "../../ui-utils/Foundation";
// pages/ucenter/my-topUp/my-topUp.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //金额
    list: [],
    activeId:0,
    //选择银行弹窗
    showActionsheet:false,
    //选择好的银行
    chooseBank: {
      icon: "../../../static/images/back_icon.png",
      name: "中国建设银行（98745）"
    },
    //银行卡列表
    bankCard: [
      {
        icon: "../../../static/images/back_icon.png",
        name: "中国农业银行储蓄（98745）"
      },
      {
        icon: "../../../static/images/back_icon.png",
        name: "中国建设银行（98745）"
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    API_Goods.getRechargenAll().then(data=>{
      data.forEach(it => {
        it.price = formatPrice(it.price);
      });
      this.setData({list:data}) ;
      this.setData({activeId:this.data.list[0].goods_id}) ;
      console.log(this.data.list,11111)
    }) 
  },
  onTab(e){
   let goods_id =  e.currentTarget.dataset.id
    this.setData({activeId:goods_id});
  },
  submit(){
    API_Trade.createRecharge({
      client: "WAP",
      rechargeId: this.data.activeId
    }).then(data => {
      wx.navigateTo({
        url: "/pages/cashier/cashier?trade_sn=" + data.trade_sn+'&isRecharge=true'
      });
    });
  },
  // 银行卡列表
  choose(){
    this.setData({showActionsheet:true})
  },
  //关闭弹窗
  close(){
    this.setData({showActionsheet:false})
  },
  //选择银行卡
  btnClickBack(event){
    this.setData({
      'chooseBank.icon':event.currentTarget.dataset.icon,
      'chooseBank.name':event.currentTarget.dataset.name,
      showActionsheet:false
    })
  },
  //添加银行卡
  addNewCard(){
    wx.navigateTo({ url: '/pages/ucenter/distribution/withdrawals-setting/withdrawals-setting' })
  },
  //提现记录
  applyHistory(){
    wx.navigateTo({ url: '/pages/ucenter/distribution/withdrawals-history/withdrawals-history' })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})